package com.lzb.musicplayer.utils;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPUtils;
import com.google.gson.reflect.TypeToken;
import com.lzb.musicplayer.bean.MusicFile;
import com.lzb.musicplayer.bean.PlayListBean;

import java.util.List;


public class AppSpUtils {
    private static final String SP_NAME = "appCollSp";
    private static final SPUtils sSpUtils = SPUtils.getInstance(SP_NAME);


    public static void savePlayList(List<PlayListBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_play_list, json);
    }

    public static List<PlayListBean> getPlayList() {
        String json = sSpUtils.getString(Key.key_play_list);
        return GsonUtils.fromJson(json, new TypeToken<List<PlayListBean>>() {
        }.getType());
    }

    public static void saveRecordList(List<MusicFile> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_record_list, json);
    }

    public static List<MusicFile> getRecordList() {
        String json = sSpUtils.getString(Key.key_record_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MusicFile>>() {
        }.getType());
    }

    interface Key {
        String key_play_list = "key_play_list";
        String key_record_list = "key_record_list";
    }
}